package com.shunya.diskorganizer;

import com.shunya.diskorganizer.tinytypes.ConfigurationValue;
import com.shunya.diskorganizer.tinytypes.ValueType;

import java.util.Collection;

import static java.lang.String.format;

public class Assertions {

    public static void assertNotNull(Object... objects) throws IllegalArgumentException {
        for (Object object : objects)
            if (object == null)
                throw new IllegalArgumentException("one or more objects were null");
    }

    public static void assertNotNullObject(String message, ConfigurationValue value) {
        assertNotNull(value);
        if (value == ConfigurationValue.NO_VALUE)
            throw new IllegalArgumentException(message);
    }

    public static void assertNotEmpty(Collection<?> collection) {
        assertNotNull(collection);
        if (collection.isEmpty())
            throw new IllegalArgumentException("collection not expected to be empty");
    }

    public static void assertStringEquals(String string, String expected) {
        if (!string.equals(expected))
            throw new IllegalArgumentException(format("unexpected string %s, expected %s", string, expected));
    }

    /*public static void assertState(Transaction transaction, TransactionState state) {
        if (transaction.getState() != state)
            throw new IllegalArgumentException(format("expected %s, found %s", state, transaction.getState()));
    }*/

    public static void verify(ValueType type) {
        if (!type.isValid())
            throw new AssertionError(format("value type %s is not valid", type.toString()));
    }

}